package net.niufei.study.cpatterns.producerconsumer;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class Resource {

	private final Queue<String> queue = new ConcurrentLinkedQueue<String>();

	public synchronized void supply(String str) {
		queue.offer(str);
		notifyAll();
	}
	
	public synchronized String fetch() throws InterruptedException {
		while(queue.size() <= 0) {
			wait();
		}
		return queue.poll();
	}
}
